package com.indexingsystem.system.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.MagazinesYearListReqVo;
import com.indexingsystem.boss.Vo.MenuPavilionColumnsVo;
import com.indexingsystem.boss.Vo.MenusRelationsVo;
import com.indexingsystem.boss.Vo.PavilionColumnsSortVo;
import com.indexingsystem.boss.Vo.PavilionColumnsVo;
import com.indexingsystem.boss.Vo.RelationsReqVo;
import com.indexingsystem.boss.Vo.ResCategorsRelationQueryVo;
import com.indexingsystem.boss.Vo.ResCategoryReqVo;
import com.indexingsystem.boss.Vo.ResourceCategorsVo;
import com.indexingsystem.boss.Vo.ResourceRelationInfoVo;
import com.indexingsystem.boss.Vo.SiteResCateReqVo;
import com.indexingsystem.boss.Vo.SpecialResourceDatasVo;
import com.indexingsystem.boss.Vo.TreeReqVo;
import com.indexingsystem.boss.Vo.WebsiteResListReqQueryVo;
import com.indexingsystem.boss.admin.mapper.PavilionsCommonMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.Books;
import com.indexingsystem.boss.entity.Games;
import com.indexingsystem.boss.entity.Magazines;
import com.indexingsystem.boss.entity.MenusRelationsInfo;
import com.indexingsystem.boss.entity.PavilionColumns;
import com.indexingsystem.boss.entity.PavilionInfo;
import com.indexingsystem.boss.entity.PavilionRelations;
import com.indexingsystem.boss.entity.ResourceByMagazines;
import com.indexingsystem.boss.entity.ResourceCategors;
import com.indexingsystem.boss.entity.ResourceType;
import com.indexingsystem.boss.entity.ResourceYear;
import com.indexingsystem.boss.entity.ResourceYearInfo;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.ResourcesInfo;
import com.indexingsystem.boss.entity.ResourcesList;
import com.indexingsystem.boss.entity.Videos;
import com.indexingsystem.boss.entity.WechatShares;
import com.indexingsystem.boss.logback.LogCvt;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.boss.utils.DateUtil;
import com.indexingsystem.boss.utils.InstitutionLoadUtils;
import com.indexingsystem.boss.utils.ListSortUtils;
import com.indexingsystem.boss.utils.SortListUtils;
import com.indexingsystem.boss.utils.StringUtil;
import com.indexingsystem.db.mongoDB.impl.ResourceCategorsResListMongo;
import com.indexingsystem.db.mongoDB.po.ResourceCategorsResPo;
import com.indexingsystem.system.service.IBooksService;
import com.indexingsystem.system.service.IGamesService;
import com.indexingsystem.system.service.IMagazinesService;
import com.indexingsystem.system.service.IPavilionsCommonService;
import com.indexingsystem.system.service.IResourceCategorsService;
import com.indexingsystem.system.service.IResourceService;
import com.indexingsystem.system.service.IResourceTypeService;
import com.indexingsystem.system.service.ISpecialResourceDatasService;
import com.indexingsystem.system.service.IVideosService;
import com.indexingsystem.system.service.IWechatSharesService;

@Service
public class PavilionsCommonServiceImpl implements IPavilionsCommonService {
	@Resource
	private IWechatSharesService			iWechatSharesService;
	@Resource
	private PavilionsCommonMapper			pavilionsCommonMapper;

	@Resource
	private IMagazinesService				magazinesService;

	@Resource
	private IBooksService					booksService;

	@Resource
	private IVideosService					videosService;

	@Resource
	private IResourceService				iResourceService;

	@Resource
	private ISpecialResourceDatasService	iSpecialResourceDatasService;

	@Resource
	private IResourceCategorsService		iResourceCategorsService;

	@Resource
	private IResourceTypeService			iResourceTypeService;

	@Resource
	private IGamesService					iGamesService;

	@Override
	public List<PavilionInfo> getPavilionsList() {
		return pavilionsCommonMapper.getPavilionsList();
	}

	/**
	 * 通过资源分类获取所有子级资源分类含自己的所有资源列表.
	 * 
	 * @param resCategoryId
	 * @return
	 */
	private List<ResourceRelationInfoVo> getResListByResCategoryId(String resCategoryId, Integer pageNumber, Integer pageSize) {

		List<ResourceCategors> resCategorsList = null;
		List<String> resCategoryIdList = null;
		ResCategorsRelationQueryVo resCategorsRelationQueryVo = null;
		List<ResourceRelationInfoVo> resourceRelationInfoVoList = null;
		Set<ResourceRelationInfoVo> resRelationSet = null;
		List<ResourceRelationInfoVo> resultResRealtionList = null;
		try {
			ResourceCategors resourceCategors = iResourceCategorsService.selectByPrimaryKey( resCategoryId );
			if (null != resourceCategors) {
				resCategorsList = iResourceCategorsService.getOrderResourceCategorsListByCategoryOrder( resourceCategors.getCategoryOrder() );
				if (null != resCategorsList && resCategorsList.size() > 0) {
					resCategoryIdList = new ArrayList<String>();
					for (ResourceCategors resCategors : resCategorsList) {
						resCategoryIdList.add( resCategors.getResCategoryId() );
					}
				}
				if (null != resCategoryIdList && resCategoryIdList.size() > 0) {
					resCategorsRelationQueryVo = new ResCategorsRelationQueryVo();
					resCategorsRelationQueryVo.setResCategorsIdList( resCategoryIdList );
				}

				// 先查询mongo读取图书数据
				List<ResourceCategorsResPo> resourceCategorsResPoList = ResourceCategorsResListMongo.findResourceCategorsResListByPage(
						resCategoryIdList, pageNumber, pageSize, InstitutionLoadUtils.getString( "institutionId" ) );
				if (null != resourceCategorsResPoList && resourceCategorsResPoList.size() > 0) {
					resultResRealtionList = new ArrayList<ResourceRelationInfoVo>();
					for (ResourceCategorsResPo resourceCategorsResPo : resourceCategorsResPoList) {
						ResourceRelationInfoVo resourceRelationInfoVo = new ResourceRelationInfoVo();
						resourceRelationInfoVo.setResCategoryId( resourceCategorsResPo.getResCategoryId() );
						resourceRelationInfoVo.setCategoryName( resourceCategorsResPo.getResCategoryName() );
						resourceRelationInfoVo.setPublishDate( resourceCategorsResPo.getPublishDate() );

						resourceRelationInfoVo.setResId( resourceCategorsResPo.getResId() );
						resourceRelationInfoVo.setResName( resourceCategorsResPo.getResName() );
						resourceRelationInfoVo.setResTypeId( resourceCategorsResPo.getResTypeId() );
						resourceRelationInfoVo.setThumbnail( resourceCategorsResPo.getThumbnail() );
						resultResRealtionList.add( resourceRelationInfoVo );
					}

				} else {
					resourceRelationInfoVoList = iResourceCategorsService.getResourceRelaInfoVoListByResCategoryIdlist( resCategorsRelationQueryVo );
					if (null != resourceRelationInfoVoList && resourceRelationInfoVoList.size() > 0) {
						resRelationSet = new HashSet<ResourceRelationInfoVo>();
						for (ResourceRelationInfoVo resRelationVo : resourceRelationInfoVoList) {
							if (!resRelationSet.contains( resRelationVo )) {
								resRelationSet.add( resRelationVo );
							}
						}
					}
					if (null != resRelationSet && resRelationSet.size() > 0) {
						resultResRealtionList = new ArrayList<ResourceRelationInfoVo>();
						for (ResourceRelationInfoVo setResRelationVo : resRelationSet) {
							resultResRealtionList.add( setResRelationVo );
						}
					}

					if (null != resultResRealtionList && resultResRealtionList.size() > 0) {
						ListSortUtils.ListSort( resultResRealtionList );
					}
				}
			}
		} catch (Exception ex) {
			LogCvt.error( ex.getMessage(), ex );
		}
		return resultResRealtionList;
	}

	/**
	 * 获取图书、动画、非洲动物资源列表总数.
	 * 
	 * @param relationsReqVo
	 * @return
	 */
	@Override
	public Integer getMenusResourcesListMaxCount(RelationsReqVo relationsReqVo) {
		List<ResourceRelationInfoVo> resourceRelationsInfoVoList = null;
		List<MenusRelationsVo> menusRelationsVoList = null;
		String pavilionId = relationsReqVo.getPavilionId();
		List<ResourcesList> resultResourcesList = null;
		// 通过分馆Id获取栏目信息
		Integer pageSize = relationsReqVo.getPageSize();

		List<PavilionColumns> pavilionColumnsList = pavilionsCommonMapper.getPavilionsInfo( pavilionId );
		if (null != pavilionColumnsList && pavilionColumnsList.size() > 0) {
			for (PavilionColumns pavilionColumn : pavilionColumnsList) {
				// 1:首次加载，2：更多加载
				if (relationsReqVo.getOptype() == 1) {
					// 通过栏目id获取资源分类list
					Integer pageNo = relationsReqVo.getPageNumber() == null ? 1 : relationsReqVo.getPageNumber();
					pageSize = relationsReqVo.getPageSize() == null ? 5 : relationsReqVo.getPageSize();
					// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
					PageHelper.startPage( pageNo, pageSize );

					Integer resType = Integer.valueOf( relationsReqVo.getResType() );
					if (resType != 1) {
						// 通过菜单查询所有分类
						menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

						// 通过分类查询所有资源
						if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
							resultResourcesList = new ArrayList<ResourcesList>();
							for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {
								PavilionRelations pavilionRelations = new PavilionRelations();
								pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
								pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
								resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(), pageNo, pageSize );
								if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
									for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {
										ResourcesList resourcesList = new ResourcesList();
										resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
										resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
										resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );
										resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );
										resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
										resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
										resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
										resourcesList.setResType( 2 );
										if (!resultResourcesList.contains( resourcesList )) {
											resultResourcesList.add( resourcesList );
										}
									}
								}
							}
						}
					}
				} else {
					if (relationsReqVo.getMenuId().equals( pavilionColumn.getMenuId() )) {
						// 通过栏目id获取资源分类list
						Integer pageNo = relationsReqVo.getPageNumber() == null ? 1 : relationsReqVo.getPageNumber();
						pageSize = relationsReqVo.getPageSize() == null ? 5 : relationsReqVo.getPageSize();
						// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
						PageHelper.startPage( pageNo, pageSize );
						Integer resType = Integer.valueOf( relationsReqVo.getResType() );
						if (resType != 1) {
							// 通过菜单查询所有分类
							menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

							// 通过分类查询所有资源
							if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
								resultResourcesList = new ArrayList<ResourcesList>();
								for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {
									PavilionRelations pavilionRelations = new PavilionRelations();
									pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
									pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
									resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(), pageNo, pageSize );
									if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
										for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {
											ResourcesList resourcesList = new ResourcesList();
											resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
											resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
											resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );
											resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );
											resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
											resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
											resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
											resourcesList.setResType( 2 );
											if (!resultResourcesList.contains( resourcesList )) {
												resultResourcesList.add( resourcesList );
											}
										}
									}
								}

							}
						}
					}
				}
			}
		}
		return resultResourcesList.size();
	}

	/**
	 * 图书、动画、非洲动物资源列表获取.
	 * 
	 * @param relationsReqVo
	 * @return
	 */
	@Override
	public List<MenuPavilionColumnsVo> getMenusResourcesList(RelationsReqVo relationsReqVo) {
		List<ResourceRelationInfoVo> resourceRelationsInfoVoList = null;
		List<MenusRelationsVo> menusRelationsVoList = null;

		MenuPavilionColumnsVo menuPavilionColumnsVo = null;

		String pavilionId = relationsReqVo.getPavilionId();
		List<ResourcesList> resultResourcesList = null;
		List<ResourcesList> targetResourcesList = null;

		List<ResourcesList> tempResourcesList = null;
		PagedResult<ResourcesList> pageResources = null;

		List<MenuPavilionColumnsVo> menuPavilionColumnsVoList = null;

		// 通过分馆Id获取栏目信息
		Integer pageSize = relationsReqVo.getPageSize();
		Integer pageNumber = relationsReqVo.getPageNumber();

		List<PavilionColumns> pavilionColumnsList = pavilionsCommonMapper.getPavilionsInfo( pavilionId );
		if (null != pavilionColumnsList && pavilionColumnsList.size() > 0) {
			menuPavilionColumnsVoList = new ArrayList<MenuPavilionColumnsVo>();
			for (PavilionColumns pavilionColumn : pavilionColumnsList) {
				menuPavilionColumnsVo = new MenuPavilionColumnsVo();
				menuPavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
				menuPavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
				menuPavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
				menuPavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
				menuPavilionColumnsVo.setParentId( pavilionColumn.getParentId() );
				// 1:首次加载，2：更多加载
				if (relationsReqVo.getOptype() == 1) {
					// 通过栏目id获取资源分类list
					Integer pageNo = relationsReqVo.getPageNumber() == null ? 1 : relationsReqVo.getPageNumber();
					pageSize = relationsReqVo.getPageSize() == null ? 5 : relationsReqVo.getPageSize();
					// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
					PageHelper.startPage( pageNo, pageSize );

					Integer resType = Integer.valueOf( relationsReqVo.getResType() );
					if (resType != 1) {
						// 通过菜单查询所有分类
						menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

						// 通过分类查询所有资源
						if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
							resultResourcesList = new ArrayList<ResourcesList>();
							for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {
								PavilionRelations pavilionRelations = new PavilionRelations();
								pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
								pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
								resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(), pageNo, pageSize );
								if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
									for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {
										ResourcesList resourcesList = new ResourcesList();
										resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
										resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
										resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );

										// 通过资源类型获取原图
										ResourceType resourceType = iResourceTypeService.selectByPrimaryKey( resourceRelaitonInfoVo.getResTypeId() );
										if (null != resourceType) {
											if (resourceType.getResTable().equals( "Books" )) {
												Books books = booksService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
												if (null != books) {
													if (StringUtils.isNotBlank( books.getFrontCover() )) {
														resourcesList.setThumbnail( books.getFrontCover() );
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else {
													resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
												}
											} else if (resourceType.getResTable().equals( "Pictures" )
													|| resourceType.getResTable().equals( "Videos" )) {
												Videos videos = videosService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
												if (null != videos) {
													if (StringUtils.isNotBlank( videos.getFrontCover() )) {
														resourcesList.setThumbnail( videos.getFrontCover() );
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else {
													resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
												}
											} else if (resourceType.getResTable().equals( "Games" )) {
												Games games = iGamesService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
												if (null != games) {
													if (StringUtils.isNotBlank( games.getFrontCover() )) {
														resourcesList.setThumbnail( games.getFrontCover() );
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else {
													resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
												}
											}
										}

										resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );
										resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
										resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
										resourcesList.setResType( 2 );
										if (!resultResourcesList.contains( resourcesList )) {
											resultResourcesList.add( resourcesList );
										}
									}
								}
							}

						}
					}

					Integer length = 0;
					Integer init = 0;
					if (null != resultResourcesList && resultResourcesList.size() > 0) {
						targetResourcesList = new ArrayList<ResourcesList>();
						if (resultResourcesList.size() >= pageSize) {
							length = pageSize;
						} else {
							length = resultResourcesList.size();
						}

						if (pageNumber - 1 > 0) {
							init = pageSize * (pageNumber - 1);
						} else {
							init = 0;
						}

						int k = 0;
						for (int j = init; k < length && j < resultResourcesList.size(); j++) {
							k++;
							targetResourcesList.add( resultResourcesList.get( j ) );
						}
						pageResources = BeanUtils.orderToPagedResult( targetResourcesList );
					} else {
						resultResourcesList = new ArrayList<ResourcesList>();
						pageResources = BeanUtils.toPagedResult( resultResourcesList );
					}

					tempResourcesList = pageResources.getDataList();
					menuPavilionColumnsVo.setMaxCount( resultResourcesList.size() );
					menuPavilionColumnsVo.setResourcesList( tempResourcesList );
					menuPavilionColumnsVoList.add( menuPavilionColumnsVo );
				} else {
					if (relationsReqVo.getMenuId().equals( pavilionColumn.getMenuId() )) {
						// 通过栏目id获取资源分类list
						// Integer pageNo = relationsReqVo.getPageNumber() ==
						// null ? 1: relationsReqVo.getPageNumber();
						// pageSize = relationsReqVo.getPageSize() == null ? 5:
						// relationsReqVo.getPageSize();
						// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
						// PageHelper.startPage(pageNo, pageSize);
						Integer resType = Integer.valueOf( relationsReqVo.getResType() );
						if (resType != 1) {
							// 通过菜单查询所有分类
							menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

							// 通过分类查询所有资源
							if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
								resultResourcesList = new ArrayList<ResourcesList>();
								for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {
									PavilionRelations pavilionRelations = new PavilionRelations();
									pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
									pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
									resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(),
											relationsReqVo.getPageNumber(), relationsReqVo.getPageSize() );
									if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
										for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {
											ResourcesList resourcesList = new ResourcesList();
											resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
											resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
											resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );
											resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );

											// 通过资源类型获取原图
											ResourceType resourceType = iResourceTypeService.selectByPrimaryKey( resourceRelaitonInfoVo
													.getResTypeId() );
											if (null != resourceType) {
												if (resourceType.getResTable().equals( "Books" )) {
													Books books = booksService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != books) {
														if (StringUtils.isNotBlank( books.getFrontCover() )) {
															resourcesList.setThumbnail( books.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else if (resourceType.getResTable().equals( "Pictures" )
														|| resourceType.getResTable().equals( "Videos" )) {
													Videos videos = videosService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != videos) {
														if (StringUtils.isNotBlank( videos.getFrontCover() )) {
															resourcesList.setThumbnail( videos.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else if (resourceType.getResTable().equals( "Games" )) {
													Games games = iGamesService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != games) {
														if (StringUtils.isNotBlank( games.getFrontCover() )) {
															resourcesList.setThumbnail( games.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												}
											}
											resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
											resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
											resourcesList.setResType( 2 );
											if (!resultResourcesList.contains( resourcesList )) {
												resultResourcesList.add( resourcesList );
											}
										}
									}
								}

							}
						}

						Integer length = 0;
						Integer init = 0;
						if (null != resultResourcesList && resultResourcesList.size() > 0) {
							targetResourcesList = new ArrayList<ResourcesList>();
							if (resultResourcesList.size() >= pageSize) {
								length = pageSize;
							} else {
								length = resultResourcesList.size();
							}

							if (pageNumber - 1 > 0) {
								init = pageSize * (pageNumber - 1);
							} else {
								init = 0;
							}

							int k = 0;
							for (int j = init; k < length && j < resultResourcesList.size(); j++) {
								k++;
								targetResourcesList.add( resultResourcesList.get( j ) );
							}
							pageResources = BeanUtils.orderToPagedResult( targetResourcesList );
						} else {
							resultResourcesList = new ArrayList<ResourcesList>();
							pageResources = BeanUtils.toPagedResult( resultResourcesList );
						}

						tempResourcesList = pageResources.getDataList();
						menuPavilionColumnsVo.setMaxCount( resultResourcesList.size() );
						menuPavilionColumnsVo.setResourcesList( tempResourcesList );
						menuPavilionColumnsVoList.add( menuPavilionColumnsVo );
					}
				}
			}
		}

		return menuPavilionColumnsVoList;
	}

	/**
	 * 图书、动画、非洲动物资源列表获取.
	 * 
	 * @param relationsReqVo
	 * @return
	 */
	@Override
	public List<MenuPavilionColumnsVo> getMenusResourcesListForWebChart(RelationsReqVo relationsReqVo) {
		List<ResourceRelationInfoVo> resourceRelationsInfoVoList = null;
		List<MenusRelationsVo> menusRelationsVoList = null;

		MenuPavilionColumnsVo menuPavilionColumnsVo = null;

		String pavilionId = relationsReqVo.getPavilionId();
		List<ResourcesList> resultResourcesList = null;
		List<ResourcesList> targetResourcesList = null;

		List<ResourcesList> tempResourcesList = null;
		PagedResult<ResourcesList> pageResources = null;

		List<MenuPavilionColumnsVo> menuPavilionColumnsVoList = null;

		// 通过分馆Id获取栏目信息
		Integer pageSize = relationsReqVo.getPageSize();
		Integer pageNumber = relationsReqVo.getPageNumber();

		List<PavilionColumns> pavilionColumnsList = pavilionsCommonMapper.getPavilionsInfo( pavilionId );
		if (null != pavilionColumnsList && pavilionColumnsList.size() > 0) {
			menuPavilionColumnsVoList = new ArrayList<MenuPavilionColumnsVo>();
			for (PavilionColumns pavilionColumn : pavilionColumnsList) {
				menuPavilionColumnsVo = new MenuPavilionColumnsVo();
				menuPavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
				menuPavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
				menuPavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
				menuPavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
				menuPavilionColumnsVo.setParentId( pavilionColumn.getParentId() );
				// 1:首次加载，2：更多加载
				if (relationsReqVo.getOptype() == 1) {
					// 通过栏目id获取资源分类list
					Integer pageNo = relationsReqVo.getPageNumber() == null ? 1 : relationsReqVo.getPageNumber();
					pageSize = relationsReqVo.getPageSize() == null ? 5 : relationsReqVo.getPageSize();
					// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
					PageHelper.startPage( pageNo, pageSize );

					Integer resType = Integer.valueOf( relationsReqVo.getResType() );
					if (resType == 1) {
						// 通过菜单查询所有分类
						menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

						// 通过分类查询所有资源
						if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
							resultResourcesList = new ArrayList<ResourcesList>();
							for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {

								PavilionRelations pavilionRelations = new PavilionRelations();
								pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
								pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
								resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(), pageNumber, pageSize );

								if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
									for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {

										ResourcesList resourcesList = new ResourcesList();
										resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
										resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
										resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );

										// 通过资源类型获取原图
										ResourceType resourceType = iResourceTypeService.selectByPrimaryKey( resourceRelaitonInfoVo.getResTypeId() );
										if (null != resourceType) {
											if (resourceType.getResTable().equals( "mobile" )) {
												WechatShares wechatShares = this.iWechatSharesService.selectByPrimaryKey( resourceRelaitonInfoVo
														.getResId() );
												if (null != wechatShares) {
													if (StringUtils.isNotBlank( wechatShares.getCoverurl() )) {
														resourcesList.setThumbnail( wechatShares.getCoverurl() );
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else {
													resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
												}
											}
										}

										resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );
										resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
										resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
										resourcesList.setResType( 1 );
										if (!resultResourcesList.contains( resourcesList )) {
											resultResourcesList.add( resourcesList );
										}
									}
								}
							}

						}
					}

					Integer length = 0;
					Integer init = 0;
					if (null != resultResourcesList && resultResourcesList.size() > 0) {
						targetResourcesList = new ArrayList<ResourcesList>();
						if (resultResourcesList.size() >= pageSize) {
							length = pageSize;
						} else {
							length = resultResourcesList.size();
						}

						if (pageNumber - 1 > 0) {
							init = pageSize * (pageNumber - 1);
						} else {
							init = 0;
						}

						int k = 0;
						for (int j = init; k < length && j < resultResourcesList.size(); j++) {
							k++;
							targetResourcesList.add( resultResourcesList.get( j ) );
						}
						pageResources = BeanUtils.orderToPagedResult( targetResourcesList );
					} else {
						resultResourcesList = new ArrayList<ResourcesList>();
						pageResources = BeanUtils.toPagedResult( resultResourcesList );
					}

					tempResourcesList = pageResources.getDataList();
					menuPavilionColumnsVo.setMaxCount( resultResourcesList.size() );
					menuPavilionColumnsVo.setResourcesList( tempResourcesList );
					menuPavilionColumnsVoList.add( menuPavilionColumnsVo );
				} else {
					if (relationsReqVo.getMenuId().equals( pavilionColumn.getMenuId() )) {
						// 通过栏目id获取资源分类list
						// Integer pageNo = relationsReqVo.getPageNumber() ==
						// null ? 1: relationsReqVo.getPageNumber();
						// pageSize = relationsReqVo.getPageSize() == null ? 5:
						// relationsReqVo.getPageSize();
						// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
						// PageHelper.startPage(pageNo, pageSize);
						Integer resType = Integer.valueOf( relationsReqVo.getResType() );
						if (resType != 1) {
							// 通过菜单查询所有分类
							menusRelationsVoList = pavilionsCommonMapper.getResCategoryListByMenuId( pavilionColumn.getMenuId() );

							// 通过分类查询所有资源
							if (null != menusRelationsVoList && menusRelationsVoList.size() > 0) {
								resultResourcesList = new ArrayList<ResourcesList>();
								for (MenusRelationsVo menusRelationsVo : menusRelationsVoList) {
									PavilionRelations pavilionRelations = new PavilionRelations();
									pavilionRelations.setResCategoryId( menusRelationsVo.getResCategoryId() );
									pavilionRelations.setResCategoryName( menusRelationsVo.getResCategoryName() );
									resourceRelationsInfoVoList = getResListByResCategoryId( menusRelationsVo.getResCategoryId(), pageNumber,
											pageSize );
									if (resourceRelationsInfoVoList != null && resourceRelationsInfoVoList.size() > 0) {
										for (ResourceRelationInfoVo resourceRelaitonInfoVo : resourceRelationsInfoVoList) {
											ResourcesList resourcesList = new ResourcesList();
											resourcesList.setResId( resourceRelaitonInfoVo.getResId() );
											resourcesList.setResName( resourceRelaitonInfoVo.getResName() );
											resourcesList.setResTypeId( resourceRelaitonInfoVo.getResTypeId() );
											resourcesList.setPublishDate( resourceRelaitonInfoVo.getPublishDate() );

											// 通过资源类型获取原图
											ResourceType resourceType = iResourceTypeService.selectByPrimaryKey( resourceRelaitonInfoVo
													.getResTypeId() );
											if (null != resourceType) {
												if (resourceType.getResTable().equals( "Books" )) {
													Books books = booksService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != books) {
														if (StringUtils.isNotBlank( books.getFrontCover() )) {
															resourcesList.setThumbnail( books.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else if (resourceType.getResTable().equals( "Pictures" )
														|| resourceType.getResTable().equals( "Videos" )) {
													Videos videos = videosService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != videos) {
														if (StringUtils.isNotBlank( videos.getFrontCover() )) {
															resourcesList.setThumbnail( videos.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												} else if (resourceType.getResTable().equals( "Games" )) {
													Games games = iGamesService.selectByPrimaryKey( resourceRelaitonInfoVo.getResId() );
													if (null != games) {
														if (StringUtils.isNotBlank( games.getFrontCover() )) {
															resourcesList.setThumbnail( games.getFrontCover() );
														} else {
															resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
														}
													} else {
														resourcesList.setThumbnail( resourceRelaitonInfoVo.getThumbnail() );
													}
												}
											}
											resourcesList.setResCategoryId( resourceRelaitonInfoVo.getResCategoryId() );
											resourcesList.setResCategoryName( pavilionColumn.getMenuTitle() );
											resourcesList.setResType( 2 );
											if (!resultResourcesList.contains( resourcesList )) {
												resultResourcesList.add( resourcesList );
											}
										}
									}
								}

							}
						}

						Integer length = 0;
						Integer init = 0;
						if (null != resultResourcesList && resultResourcesList.size() > 0) {
							targetResourcesList = new ArrayList<ResourcesList>();
							if (resultResourcesList.size() >= pageSize) {
								length = pageSize;
							} else {
								length = resultResourcesList.size();
							}

							if (pageNumber - 1 > 0) {
								init = pageSize * (pageNumber - 1);
							} else {
								init = 0;
							}

							int k = 0;
							for (int j = init; k < length && j < resultResourcesList.size(); j++) {
								k++;
								targetResourcesList.add( resultResourcesList.get( j ) );
							}
							pageResources = BeanUtils.orderToPagedResult( targetResourcesList );
						} else {
							resultResourcesList = new ArrayList<ResourcesList>();
							pageResources = BeanUtils.toPagedResult( resultResourcesList );
						}

						tempResourcesList = pageResources.getDataList();
						menuPavilionColumnsVo.setMaxCount( resultResourcesList.size() );
						menuPavilionColumnsVo.setResourcesList( tempResourcesList );
						menuPavilionColumnsVoList.add( menuPavilionColumnsVo );
					}
				}
			}
		}

		return menuPavilionColumnsVoList;
	}

	@Override
	public MenusRelationsInfo getMenusRelationsInfo(RelationsReqVo reqVo) throws Exception {
		MenusRelationsInfo menusRelationsInfo = new MenusRelationsInfo();
		List<PavilionColumnsVo> pavilionColumnsVoList = null;
		PavilionColumnsVo pavilionColumnsVo = null;
		List<PavilionRelations> pavilionRelationsList = null;
		String pavilionId = reqVo.getPavilionId();
		// 通过分馆Id获取栏目信息
		Integer maxCount = 0;
		List<PavilionColumns> pavilionColumnsList = pavilionsCommonMapper.getPavilionsInfo( pavilionId );
		if (null != pavilionColumnsList && pavilionColumnsList.size() > 0) {
			pavilionColumnsVoList = new ArrayList<PavilionColumnsVo>();
			PagedResult<PavilionRelations> pavilionRelationsPage = null;
			for (PavilionColumns pavilionColumn : pavilionColumnsList) {
				// 1:首次加载，2：更多加载
				if (reqVo.getOptype() == 1) {
					pavilionColumnsVo = new PavilionColumnsVo();
					pavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
					pavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
					pavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
					pavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
					pavilionColumnsVo.setParentId( pavilionColumn.getParentId() );

					// 通过栏目id获取资源分类list
					Integer pageNo = reqVo.getPageNumber() == null ? 1 : reqVo.getPageNumber();
					Integer pageSize = reqVo.getPageSize() == null ? 20 : reqVo.getPageSize();
					// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
					PageHelper.startPage( pageNo, pageSize );

					Integer resType = Integer.valueOf( reqVo.getResType() );

					switch (resType) {
					case 1:
						pavilionRelationsPage = BeanUtils.toPagedResult( pavilionsCommonMapper.getFiveRelationsInfo( pavilionColumn.getMenuId() ) );
						pavilionColumnsVo.setMaxCount( reqVo.getPageSize() );
						pavilionRelationsList = (List<PavilionRelations>) pavilionRelationsPage.getDataList();
						pavilionColumnsVo.setPavilionRelationsList( pavilionRelationsList );
						pavilionColumnsVoList.add( pavilionColumnsVo );
						break;

					default:
						break;
					}

				} else {
					if (reqVo.getMenuId().equals( pavilionColumn.getMenuId() )) {
						pavilionColumnsVo = new PavilionColumnsVo();
						pavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
						pavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
						pavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
						pavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
						pavilionColumnsVo.setParentId( pavilionColumn.getParentId() );

						// 通过栏目id获取资源分类list
						Integer pageNo = reqVo.getPageNumber() == null ? 1 : reqVo.getPageNumber();
						Integer pageSize = reqVo.getPageSize() == null ? 20 : reqVo.getPageSize();
						// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
						PageHelper.startPage( pageNo, pageSize );

						Integer resType = Integer.valueOf( reqVo.getResType() );
						switch (resType) {
						case 1:
							pavilionRelationsPage = BeanUtils
									.toPagedResult( pavilionsCommonMapper.getFiveRelationsInfo( pavilionColumn.getMenuId() ) );
							maxCount = pavilionsCommonMapper.getFiveRelationsInfoCount( pavilionColumn.getMenuId() );
							pavilionColumnsVo.setMaxCount( maxCount );
							pavilionRelationsList = (List<PavilionRelations>) pavilionRelationsPage.getDataList();
							pavilionColumnsVo.setPavilionRelationsList( pavilionRelationsList );
							// pavilionColumnsVo.setColumnOrderVal(columnOrderVal);
							pavilionColumnsVoList.add( pavilionColumnsVo );
							break;
						default:
							break;
						}
					}
				}
			}

			// if(null != pavilionColumnsVoList &&
			// pavilionColumnsVoList.size()>0){
			// SortListUtils<PavilionColumnsVo> pavilionColumnsVoSortList = new
			// SortListUtils<PavilionColumnsVo>();
			// pavilionColumnsVoSortList.sortByMethod(pavilionColumnsVoList,
			// "getColumnOrderVal", true);
			// }

			menusRelationsInfo.setPavilionColumnsVoList( pavilionColumnsVoList );
		}
		return menusRelationsInfo;
	}

	@Override
	public Integer getResourcesListCount(String id) {
		return pavilionsCommonMapper.getResourcesListCount( id );
	}

	@Override
	public PagedResult<ResourcesList> getResourcesList(TreeReqVo treeReqVo) {
		Integer pageNumber = treeReqVo.getPageNumber() == null ? 1 : treeReqVo.getPageNumber();
		Integer pageSize = treeReqVo.getPageSize() == null ? 10 : treeReqVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNumber, pageSize );

		List<ResourcesList> resourcesList = pavilionsCommonMapper.getResourcesList( treeReqVo.getId() );
		return BeanUtils.toPagedResult( resourcesList );
	}

	@Override
	public ResourceByMagazines getResourceByMagazines(ResCategoryReqVo resCategoryReqVo) throws Exception {
		ResourceByMagazines resourceByMagazines = null;
		String resId = resCategoryReqVo.getResId();
		LogCvt.info( new StringBuffer( "开始通过id查询期刊详情: resId=" ).append( resId ).toString() );

		// 1、通过id查询资源信息
		Resources resources = iResourceService.selectByPrimaryKey( resId );
		if (StringUtil.isNotBlank( resources )) {
			resourceByMagazines = new ResourceByMagazines();
			resourceByMagazines.setResources( resources );
		}

		// 2、查询期刊信息
		Magazines magazines = magazinesService.selectByPrimaryKey( resId );
		resourceByMagazines.setMagazines( magazines );

		// 3、期刊资源与终端信息
		List<SpecialResourceDatasVo> specialResourceDataVoResultList = iSpecialResourceDatasService.getSpecialResourceDataByResId( resId );
		resourceByMagazines.setSpecialResourceDatasVoList( specialResourceDataVoResultList );

		// 4、通过资源分类id获取资源分类所有报刊资源信息，并迭代按年分组
		List<ResourceYear> resourceYears = null;// 年Vo
		ResourceYear resourceYear = null;
		List<ResourceYearInfo> resourceYearInfos = null;// 年Vo具体资源
		List<ResourceYearInfo> resultResYearInfoList = null;

		// 先获取资源分类中报刊所有年份
		SiteResCateReqVo siteResCateReqVo = new SiteResCateReqVo();
		siteResCateReqVo.setResCategoryId( resCategoryReqVo.getResCategoryId() );
		List<Integer> initYearList = pavilionsCommonMapper.getResYearByMagazinesType( siteResCateReqVo );
		Set<Integer> yearSet = null;
		if (null != initYearList && initYearList.size() > 0) {
			yearSet = new HashSet<Integer>();
			for (Integer year : initYearList) {
				yearSet.add( year );
			}
		}
		List<Integer> yearList = new ArrayList<Integer>();
		for (Integer intVal : yearSet) {
			yearList.add( intVal );
		}
		Collections.sort( yearList, Collections.reverseOrder() );
		SiteResCateReqVo siteResCateYearVo = null;
		PagedResult<ResourceYearInfo> resourceYearInfoPage = null;
		if (yearList != null && yearList.size() > 0) {
			resourceYears = new ArrayList<ResourceYear>();// 年Vo
			for (Integer yearVal : yearList) {
				resultResYearInfoList = new ArrayList<ResourceYearInfo>();
				siteResCateYearVo = new SiteResCateReqVo();
				resourceYear = new ResourceYear();
				siteResCateYearVo.setResCategoryId( resCategoryReqVo.getResCategoryId() );
				siteResCateYearVo.setYearVal( yearVal );
				resourceYearInfoPage = getResByMagazinesTypeInfoByYear( 1, 10, siteResCateYearVo );
				resourceYearInfos = (List<ResourceYearInfo>) resourceYearInfoPage.getDataList();
				if (null != resourceYearInfos && resourceYearInfos.size() > 0) {
					for (ResourceYearInfo resYearInfo : resourceYearInfos) {
						magazines = magazinesService.selectByPrimaryKey( resYearInfo.getResId() );
						resYearInfo.setPublishDate( magazines.getYear() + "年" + magazines.getMonth() + "月" + "第" + magazines.getPeriodOfTime() + "期" );
						String magazinesPeriodOfTime = "";
						if (magazines.getPeriodOfTime().indexOf( "/" ) > -1) {
							magazinesPeriodOfTime = magazines.getPeriodOfTime().substring( 0, magazines.getPeriodOfTime().indexOf( "/" ) );
						} else {
							magazinesPeriodOfTime = magazines.getPeriodOfTime();
						}
						resYearInfo.setPeriodOfTime( Integer.valueOf( magazinesPeriodOfTime ) );
						resultResYearInfoList.add( resYearInfo );
					}
				}
				resourceYear.setResourceYearInfo( resultResYearInfoList );
				resourceYear.setYearVal( String.valueOf( yearVal ) );
				resourceYears.add( resourceYear );
			}
		}

		if (null != resourceYears && resourceYears.size() > 0) {
			SortListUtils<ResourceYearInfo> resourceYearInfoSortList = new SortListUtils<ResourceYearInfo>();
			resourceYearInfoSortList.sortByMethod( resourceYear.getResourceYearInfo(), "getPeriodOfTime", true );
			resourceYearInfoSortList.sortByMethod( resourceYear.getResourceYearInfo(), "getYear", true );
			resourceYearInfoSortList.sortByMethod( resourceYear.getResourceYearInfo(), "getMonth", true );
		}

		resourceByMagazines.setResourceYearInfos( resourceYears );
		return resourceByMagazines;
	}

	/**
	 * 通过资源id获取看绘本详情及其它绘本信息.
	 * 
	 * @param resCategoryReqVo
	 * @return
	 */
	@Override
	public ResourceByMagazines getResourceByBooks(ResCategoryReqVo resCategoryReqVo) throws Exception {
		ResourceByMagazines resourceByMagazines = null;
		String resId = resCategoryReqVo.getResId();
		PagedResult<ResourcesList> xtResListPage = null;
		PagedResult<ResourcesList> btResListPage = null;
		List<ResourcesInfo> resourceInfosList = null;
		ResourcesInfo resourceInfos = null;
		List<ResourcesList> xtResList = null;
		List<ResourcesList> btResList = null;
		LogCvt.info( new StringBuffer( "开始通过id查询绘本详情: resId=" ).append( resId ).toString() );

		// 1、通过id查询资源信息
		Resources resources = iResourceService.selectByPrimaryKey( resId );
		if (StringUtil.isNotBlank( resources )) {
			resourceInfosList = new ArrayList<ResourcesInfo>();
			resourceByMagazines = new ResourceByMagazines();
			resourceByMagazines.setResources( resources );

			// 2获取绘本、图书信息
			Books books = booksService.selectByPrimaryKey( resId );
			resourceByMagazines.setBooks( books );

			// 3、绘本、图书资源与终端信息
			List<SpecialResourceDatasVo> specialResourceDataVoResultList = iSpecialResourceDatasService.getSpecialResourceDataByResId( resId );
			resourceByMagazines.setSpecialResourceDatasVoList( specialResourceDataVoResultList );

			String titps = "";
			ResourceCategorsVo resCategorsVo = iResourceCategorsService.getResCategoryById( resCategoryReqVo.getResCategoryId() );
			if (null != resCategorsVo) {
				if (StringUtils.isNotBlank( resCategorsVo.getResName() )) {
					titps = "更多" + resCategorsVo.getResName();
				}
			}

			// 4、获取同一个分类中的除了自己本身的其它绘本、图书列表
			SiteResCateReqVo xtReqVo = new SiteResCateReqVo();
			xtReqVo.setResCategoryId( resCategoryReqVo.getResCategoryId() );
			xtReqVo.setResId( resId );
			xtResListPage = getResByBookTypeInfos( 1, 10, 1, xtReqVo );
			xtResList = xtResListPage.getDataList();
			if (null != xtResList && xtResList.size() > 0) {
				resourceInfos = new ResourcesInfo();
				resourceInfos.setColumnName( titps );
				resourceInfos.setResultType( 1 );
				resourceInfos.setResourcesList( xtResList );
				resourceInfosList.add( resourceInfos );
			}

			// 5、获取不是同一个分类的其它绘本、图书列表
			btResListPage = getResByBookTypeInfos( 1, 10, 2, xtReqVo );
			btResList = btResListPage.getDataList();
			if (null != btResList && btResList.size() > 0) {
				resourceInfos = new ResourcesInfo();
				resourceInfos.setColumnName( "更多绘本" );
				resourceInfos.setResultType( 2 );
				resourceInfos.setResourcesList( btResList );
				resourceInfosList.add( resourceInfos );
			}
		}
		resourceByMagazines.setResourceInfosList( resourceInfosList );
		return resourceByMagazines;
	}

	/**
	 * 通过资源id获取看动画详情及其它动画信息.
	 * 
	 * @param resCategoryReqVo
	 * @return
	 */
	@Override
	public ResourceByMagazines getResourceByVideos(ResCategoryReqVo resCategoryReqVo) throws Exception {
		ResourceByMagazines resourceByMagazines = null;
		String resId = resCategoryReqVo.getResId();
		PagedResult<ResourcesList> xtResListPage = null;
		PagedResult<ResourcesList> btResListPage = null;
		List<ResourcesInfo> resourceInfosList = new ArrayList<ResourcesInfo>();
		ResourcesInfo resourceInfos = null;
		List<ResourcesList> xtResList = null;
		List<ResourcesList> btResList = null;
		LogCvt.info( new StringBuffer( "开始通过id查询动画详情: resId=" ).append( resId ).toString() );

		// 1、通过id查询资源信息
		Resources resources = iResourceService.selectByPrimaryKey( resId );
		if (StringUtil.isNotBlank( resources )) {
			resourceByMagazines = new ResourceByMagazines();
			resourceByMagazines.setResources( resources );
		}

		// 2获取绘本、图书信息
		Videos videos = videosService.selectByPrimaryKey( resId );
		resourceByMagazines.setVideos( videos );

		// 3、绘本、图书资源与终端信息
		List<SpecialResourceDatasVo> specialResourceDataVoResultList = iSpecialResourceDatasService.getSpecialResourceDataByResId( resId );
		resourceByMagazines.setSpecialResourceDatasVoList( specialResourceDataVoResultList );

		String titps = "";
		ResourceCategorsVo resCategorsVo = iResourceCategorsService.getResCategoryById( resCategoryReqVo.getResCategoryId() );
		if (null != resCategorsVo) {
			if (StringUtils.isNotBlank( resCategorsVo.getResName() )) {
				titps = "更多" + resCategorsVo.getResName();
			}
		}

		// 4、获取同一个分类中的除了自己本身的其它视频列表
		SiteResCateReqVo xtReqVo = new SiteResCateReqVo();
		xtReqVo.setResCategoryId( resCategoryReqVo.getResCategoryId() );
		xtReqVo.setResId( resId );
		xtResListPage = getResByVideosTypeInfos( 1, 10, 1, xtReqVo );
		xtResList = xtResListPage.getDataList();
		if (null != xtResList && xtResList.size() > 0) {
			resourceInfos = new ResourcesInfo();
			resourceInfos.setColumnName( titps );
			resourceInfos.setResultType( 1 );
			resourceInfos.setResourcesList( xtResList );
			resourceInfosList.add( resourceInfos );
		}

		// 5、获取不是同一个分类的其它视频列表
		btResListPage = getResByVideosTypeInfos( 1, 10, 2, xtReqVo );
		btResList = btResListPage.getDataList();
		if (null != btResList && btResList.size() > 0) {
			resourceInfos = new ResourcesInfo();
			resourceInfos.setColumnName( "更多动画" );
			resourceInfos.setResultType( 2 );
			resourceInfos.setResourcesList( btResList );
			resourceInfosList.add( resourceInfos );
		}
		resourceByMagazines.setResourceInfosList( resourceInfosList );
		return resourceByMagazines;
	}

	/**
	 * 通过年及资源分类id获取该分类下同一年的报刊资源集合.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public PagedResult<ResourceYearInfo> getResByMagazinesTypeInfoByYear(Integer pageNo, Integer pageSize, SiteResCateReqVo siteResCateReqVo) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( pavilionsCommonMapper.getResByMagazinesTypeInfoByYear( siteResCateReqVo ) );
	}

	/**
	 * 获取同一个分类的其它绘本或不为同一个分类的其它分类的绘本集合.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public PagedResult<ResourcesList> getResByBookTypeInfos(Integer pageNo, Integer pageSize, Integer resultType, SiteResCateReqVo siteResCateReqVo)
			throws Exception {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		List<ResourcesList> resourcesList = null;
		if (resultType == 1) {
			// 如果resultType = 1为同一个分类的其它绘本集合
			resourcesList = pavilionsCommonMapper.getIdenticalResByBooksTypeInfos( siteResCateReqVo );
		}
		if (resultType == 2) {
			// 如果resultType = 2为其它分类的其它绘本集合
			resourcesList = pavilionsCommonMapper.getNotIdenticalResByBooksTypeInfos( siteResCateReqVo );
		}
		return BeanUtils.toPagedResult( resourcesList );
	}

	/**
	 * 通过资源分类id和year获取同一个资源分类id同一个年的报刊资源列表.
	 * 
	 * @param magazinesYearListReqVo
	 * @return
	 */
	@Override
	public PagedResult<ResourceYearInfo> getMagazinesYearListByPage(MagazinesYearListReqVo magazinesYearListReqVo) {
		Integer pageNo = magazinesYearListReqVo.getPageNumber() == null ? 1 : magazinesYearListReqVo.getPageNumber();
		Integer pageSize = magazinesYearListReqVo.getPageSize() == null ? 10 : magazinesYearListReqVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );

		SiteResCateReqVo siteResCateReqVo = new SiteResCateReqVo();
		siteResCateReqVo.setResCategoryId( magazinesYearListReqVo.getResCategoryId() );
		siteResCateReqVo.setYearVal( Integer.valueOf( magazinesYearListReqVo.getYear() ) );
		return BeanUtils.toPagedResult( pavilionsCommonMapper.getResByMagazinesTypeInfoByYear( siteResCateReqVo ) );
	}

	/**
	 * 通过资源分类id和year获取同一个资源分类id同一个年的报刊资源列表总数.
	 * 
	 * @param magazinesYearListReqVo
	 * @return
	 */
	@Override
	public Integer getMagazinesYearListCount(MagazinesYearListReqVo magazinesYearListReqVo) {
		SiteResCateReqVo siteResCateReqVo = new SiteResCateReqVo();
		siteResCateReqVo.setResCategoryId( magazinesYearListReqVo.getResCategoryId() );
		siteResCateReqVo.setYearVal( Integer.valueOf( magazinesYearListReqVo.getYear() ) );
		return pavilionsCommonMapper.getMagazinesYearListCount( siteResCateReqVo );
	}

	/**
	 * 获取同一个分类的其它绘本或不为同一个分类的其它分类的绘本集合.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public PagedResult<ResourcesList> getResByVideosTypeInfos(Integer pageNo, Integer pageSize, Integer resultType, SiteResCateReqVo siteResCateReqVo)
			throws Exception {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		List<ResourcesList> resourcesList = null;
		if (resultType == 1) {
			// 如果resultType = 1为同一个分类的其它绘本集合
			resourcesList = pavilionsCommonMapper.getIdenticalResByVideosTypeInfos( siteResCateReqVo );
		}
		if (resultType == 2) {
			// 如果resultType = 2为其它分类的其它绘本集合
			resourcesList = pavilionsCommonMapper.getNotIdenticalResByVideosTypeInfos( siteResCateReqVo );
		}
		return BeanUtils.toPagedResult( resourcesList );
	}

	/**
	 * 通过资源分类id获取同一个分类中其它绘本资源列表总数.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public Integer getIdenticalResByBooksTypeInfosCount(SiteResCateReqVo siteResCateReqVo) {
		return pavilionsCommonMapper.getIdenticalResByBooksTypeInfosCount( siteResCateReqVo );
	}

	/**
	 * 通过资源分类id获取不同分类中其它绘本资源列表总数.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public Integer getNotIdenticalResByBooksTypeInfosCount(SiteResCateReqVo siteResCateReqVo) {
		return pavilionsCommonMapper.getNotIdenticalResByBooksTypeInfosCount( siteResCateReqVo );
	}

	/**
	 * 通过资源分类id获取同一个分类中其它动画资源列表总数.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public Integer getIdenticalResByVideoTypeInfosCount(SiteResCateReqVo siteResCateReqVo) {
		return pavilionsCommonMapper.getIdenticalResByVideoTypeInfosCount( siteResCateReqVo );
	}

	/**
	 * 通过资源分类id获取不同分类中其它动画资源列表总数.
	 * 
	 * @param siteResCateReqVo
	 * @return
	 */
	@Override
	public Integer getNotIdenticalResByVideoTypeInfosCount(SiteResCateReqVo siteResCateReqVo) {
		return pavilionsCommonMapper.getNotIdenticalResByVideoTypeInfosCount( siteResCateReqVo );
	}

	/**
	 * 通过资源分类id获取报刊资源列表信息
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public PagedResult<ResourcesList> getMagazinesTypeResourcesListByResCategoryId(WebsiteResListReqQueryVo resListQueryVo) throws Exception {
		List<ResourceCategorsResPo> resCategorysResPo = ResourceCategorsResListMongo.findResourceCategorsResListByPage(
				resListQueryVo.getResCategoryIdList(), resListQueryVo.getPageNumber(), resListQueryVo.getPageSize(),
				InstitutionLoadUtils.getString( "institutionId" ) );
		// 如果查询mongo有数据，就直接查询mongoDB带分页
		List<ResourcesList> resourcesList = null;
		List<ResourceCategorsResPo> resourceCategorsResPoList = null;
		if (null != resCategorysResPo && resCategorysResPo.size() > 0) {
			resourcesList = new ArrayList<ResourcesList>();
			for (ResourceCategorsResPo resCategorsResPo : resCategorysResPo) {
				ResourcesList resources = new ResourcesList();
				resources.setDatePx( resCategorsResPo.getDatePx() );
				resources.setPeriodOfTime( resCategorsResPo.getPeriodOfTime() );
				resources.setPublishDate( resCategorsResPo.getPublishDate() );
				resources.setResCategoryId( resCategorsResPo.getResCategoryId() );
				resources.setResCategoryName( resCategorsResPo.getResCategoryName() );
				resources.setResId( resCategorsResPo.getResId() );
				resources.setResName( resCategorsResPo.getResName() );
				resources.setResType( resCategorsResPo.getResType() );
				resources.setResTypeId( resCategorsResPo.getResTypeId() );
				resources.setThumbnail( resCategorsResPo.getThumbnail() );
				resources.setStatus( resCategorsResPo.getStatus() );
				if (!resourcesList.contains( resources )) {
					resourcesList.add( resources );
				}
			}
		} else {
			List<ResourcesList> queryResourcesList = pavilionsCommonMapper.getMagazinesTypeResourcesListByResCategoryId( resListQueryVo
					.getResCategoryIdList() );
			// 通过查询mongo分页无数据，就获取mysql分页查询 :全部存储到mongoDB中，不带分页
			if (null != queryResourcesList && queryResourcesList.size() > 0) {
				resourceCategorsResPoList = new ArrayList<ResourceCategorsResPo>();
				for (ResourcesList resourcesObj : queryResourcesList) {
					ResourceCategorsResPo resourceCategorsResPo = new ResourceCategorsResPo();
					resourceCategorsResPo.setDatePx( resourcesObj.getDatePx() );
					resourceCategorsResPo.setPeriodOfTime( resourcesObj.getPeriodOfTime() );
					// resourceCategorsResPo.setPublishDate(
					// resourcesObj.getPublishDate() );
					resourceCategorsResPo.setResCategoryId( resourcesObj.getResCategoryId() );
					resourceCategorsResPo.setResCategoryName( resourcesObj.getResCategoryName() );
					resourceCategorsResPo.setResId( resourcesObj.getResId() );
					resourceCategorsResPo.setResName( resourcesObj.getResName() );
					resourceCategorsResPo.setResType( resourcesObj.getResType() );
					resourceCategorsResPo.setResTypeId( resourcesObj.getResTypeId() );

					resourceCategorsResPo.setResTable( "Magazines" );

					ResourceType resourceType = iResourceTypeService.selectByPrimaryKey( resourcesObj.getResTypeId() );
					Magazines magazines = magazinesService.selectByPrimaryKey( resourcesObj.getResId() );
					if (resourceType.getResTable().equals( "Magazines" )) {
						resourceCategorsResPo.setThumbnail( magazines.getFrontCover() );
						resourceCategorsResPo.setResType( 1 );
						String publishDate = magazines.getYear() + "年" + magazines.getMonth() + "月" + "第" + magazines.getPeriodOfTime() + "期";

						String month = "";
						if (magazines.getMonth() < 10) {
							month = "0" + magazines.getMonth().toString();
							// dd = "01";
						} else {
							month = magazines.getMonth().toString();
						}

						String dateValue = magazines.getYear() + "-" + month + "-" + "01";
						resourceCategorsResPo.setDatePx( DateUtil.parseFormatToPublishDate( dateValue ) );
						resourceCategorsResPo.setPublishDate( publishDate );
						resourceCategorsResPo.setStatus( resourcesObj.getStatus() );
					}
					if (!resourceCategorsResPoList.contains( resourceCategorsResPo )) {
						resourceCategorsResPoList.add( resourceCategorsResPo );
					}
				}
			}
			// 存储更新到mongo
			if (null != resourceCategorsResPoList && resourceCategorsResPoList.size() > 0) {
				ResourceCategorsResListMongo
						.addResourceCategorsResList( resourceCategorsResPoList, InstitutionLoadUtils.getString( "institutionId" ) );
			}

			resCategorysResPo = ResourceCategorsResListMongo.findResourceCategorsResListByPage( resListQueryVo.getResCategoryIdList(),
					resListQueryVo.getPageNumber(), resListQueryVo.getPageSize(), InstitutionLoadUtils.getString( "institutionId" ) );
			resourcesList = new ArrayList<ResourcesList>();
			// 如果查询mongo有数据，就直接查询mongoDB带分页
			if (null != resCategorysResPo && resCategorysResPo.size() > 0) {
				for (ResourceCategorsResPo resCategorsResPo : resCategorysResPo) {
					ResourcesList resources = new ResourcesList();
					resources.setDatePx( resCategorsResPo.getDatePx() );
					resources.setPeriodOfTime( resCategorsResPo.getPeriodOfTime() );
					resources.setPublishDate( resCategorsResPo.getPublishDate() );
					resources.setResCategoryId( resCategorsResPo.getResCategoryId() );
					resources.setResCategoryName( resCategorsResPo.getResCategoryName() );
					resources.setResId( resCategorsResPo.getResId() );
					resources.setResName( resCategorsResPo.getResName() );
					resources.setResType( resCategorsResPo.getResType() );
					resources.setResTypeId( resCategorsResPo.getResTypeId() );
					resources.setThumbnail( resCategorsResPo.getThumbnail() );
					resources.setStatus( resCategorsResPo.getStatus() );
					if (!resourcesList.contains( resources )) {
						resourcesList.add( resources );
					}
				}
			}
			Integer pageNo = resListQueryVo.getPageNumber() == null ? 1 : resListQueryVo.getPageNumber();
			Integer pageSize = resListQueryVo.getPageSize() == null ? 10 : resListQueryVo.getPageSize();
			// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
			PageHelper.startPage( pageNo, pageSize );
			// resourcesList = queryResourcesList;
		}
		return BeanUtils.toPagedResult( resourcesList );
	}

	/**
	 * 通过资源分类id获取报刊资源列表总数.
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public Integer getMagazinesTypeResCount(WebsiteResListReqQueryVo resListQueryVo) throws Exception {
		Integer maxCount = 0;
		maxCount = ResourceCategorsResListMongo.findResourceCategorsResListCount( resListQueryVo.getResCategoryIdList(),
				InstitutionLoadUtils.getString( "institutionId" ) );
		if (maxCount == 0) {
			maxCount = pavilionsCommonMapper.getMagazinesTypeResCount( resListQueryVo.getResCategoryIdList() );
		}
		return maxCount;
	}

	/**
	 * 通过资源分类id获取绘本资源列表信息
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public PagedResult<ResourcesList> getBooksTypeResourcesListByResCategoryId(WebsiteResListReqQueryVo resListQueryVo) {
		Integer pageNo = resListQueryVo.getPageNumber() == null ? 1 : resListQueryVo.getPageNumber();
		Integer pageSize = resListQueryVo.getPageSize() == null ? 10 : resListQueryVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( pavilionsCommonMapper.getBooksTypeResourcesListByResCategoryId( resListQueryVo.getResCategoryIdList() ) );
	}

	/**
	 * 通过资源分类id获取绘本资源列表总数.
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public Integer getBooksTypeResCount(WebsiteResListReqQueryVo resListQueryVo) {
		return pavilionsCommonMapper.getBooksTypeResCount( resListQueryVo.getResCategoryIdList() );
	}

	/**
	 * 通过资源分类id获取动画资源列表信息
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public PagedResult<ResourcesList> getVideosTypeResourcesListByResCategoryId(WebsiteResListReqQueryVo resListQueryVo) {
		Integer pageNo = resListQueryVo.getPageNumber() == null ? 1 : resListQueryVo.getPageNumber();
		Integer pageSize = resListQueryVo.getPageSize() == null ? 10 : resListQueryVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( pavilionsCommonMapper.getVideosTypeResourcesListByResCategoryId( resListQueryVo.getResCategoryIdList() ) );
	}

	/**
	 * 通过资源分类id获取动画资源列表总数.
	 * 
	 * @param resCategoryId
	 * @return
	 */
	@Override
	public Integer getVideosTypeResCount(WebsiteResListReqQueryVo resListQueryVo) {
		return pavilionsCommonMapper.getVideosTypeResCount( resListQueryVo.getResCategoryIdList() );
	}

	@Override
	public List<PavilionColumns> getPavilionColumnsListByCondition(PavilionColumnsSortVo pavilionColumnsSortVo) {
		// TODO Auto-generated method stub
		return pavilionsCommonMapper.getPavilionColumnsListByCondition( pavilionColumnsSortVo );
	}

	@Override
	public void updatePavilionColumnsListByCondition(PavilionColumnsSortVo pavilionColumnsSortVo) {
		// TODO Auto-generated method stub
		pavilionsCommonMapper.updatePavilionColumnsListByCondition( pavilionColumnsSortVo );
	}

	@Override
	public MenusRelationsInfo getMenusRelationsInfoForWebChat(RelationsReqVo reqVo) throws Exception {
		MenusRelationsInfo menusRelationsInfo = new MenusRelationsInfo();
		List<PavilionColumnsVo> pavilionColumnsVoList = null;
		PavilionColumnsVo pavilionColumnsVo = null;
		List<PavilionRelations> pavilionRelationsList = null;
		List<PavilionRelations> targetPavilionRelationsList = null;
		String pavilionId = reqVo.getPavilionId();
		ResourceBundle resource = ResourceBundle.getBundle( "application" );
		String getStaticPath = resource.getString( "getStaticPath" ).trim();
		// 通过分馆Id获取栏目信息
		Integer maxCount = 0;
		List<PavilionColumns> pavilionColumnsList = pavilionsCommonMapper.getPavilionsInfo( pavilionId );
		if (null != pavilionColumnsList && pavilionColumnsList.size() > 0) {
			pavilionColumnsVoList = new ArrayList<PavilionColumnsVo>();
			PagedResult<PavilionRelations> pavilionRelationsPage = null;
			for (PavilionColumns pavilionColumn : pavilionColumnsList) {
				// 1:首次加载，2：更多加载
				if (reqVo.getOptype() == 1) {
					pavilionColumnsVo = new PavilionColumnsVo();
					pavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
					pavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
					pavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
					pavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
					pavilionColumnsVo.setParentId( pavilionColumn.getParentId() );

					// 通过栏目id获取资源分类list
					Integer pageNo = reqVo.getPageNumber() == null ? 1 : reqVo.getPageNumber();
					Integer pageSize = reqVo.getPageSize() == null ? 5 : reqVo.getPageSize();
					// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
					PageHelper.startPage( pageNo, pageSize );

					Integer resType = Integer.valueOf( reqVo.getResType() );

					switch (resType) {
					case 1:
						pavilionRelationsPage = BeanUtils.toPagedResult( pavilionsCommonMapper.getFiveRelationsInfoForWebChat( pavilionColumn
								.getMenuId() ) );
						pavilionColumnsVo.setMaxCount( pavilionRelationsPage.getDataList().size() );
						pavilionRelationsList = (List<PavilionRelations>) pavilionRelationsPage.getDataList();
						if (pavilionRelationsPage != null && pavilionRelationsPage.getDataList().size() >= 6) {
							pavilionColumnsVo.setMore( true );
						} else {
							pavilionColumnsVo.setMore( false );
						}
						pavilionColumnsVo.setPageno( pageNo );
						targetPavilionRelationsList = new ArrayList<PavilionRelations>();
						if (null != pavilionRelationsList && pavilionRelationsList.size() > 0) {
							for (PavilionRelations pavilionRelationsObjVo : pavilionRelationsList) {
								// 五报
								if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianbao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国儿童报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoertongbao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年英语报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianyinyubao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国儿童画报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoertonghuabao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国中学生报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguozhongxueshengbao.jpg" );
								}

								// 十三刊
								else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "幼儿画报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/youerhuabao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "婴儿画报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/yinerhuabao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "嘟嘟熊画报" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/duduxionghuabao.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "我们爱科学" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/womenaikexue.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "儿童文学" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/ertongwenxue.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国卡通" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguokatong.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年儿童" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianertong.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年文摘" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianwenzhai.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中学生" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongxuesheng.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "智力课堂" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhiliketang.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "知心姐姐" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhixinjiejie.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "辅导员" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/fudaoyuan.jpg" );
								} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "少先队小干部" )) {
									pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/shaoxianduixiaoganbu.jpg" );
								} else {
									continue;
								}
								targetPavilionRelationsList.add( pavilionRelationsObjVo );
							}
						}
						pavilionColumnsVo.setPavilionRelationsList( targetPavilionRelationsList );
						pavilionColumnsVoList.add( pavilionColumnsVo );

						break;

					default:
						break;
					}

				} else {
					if (reqVo.getMenuId().equals( pavilionColumn.getMenuId() )) {
						pavilionColumnsVo = new PavilionColumnsVo();
						pavilionColumnsVo.setMenuId( pavilionColumn.getMenuId() );
						pavilionColumnsVo.setMenuTitle( pavilionColumn.getMenuTitle() );
						pavilionColumnsVo.setColumnOrder( pavilionColumn.getColumnOrder() );
						pavilionColumnsVo.setIsSpecial( pavilionColumn.getIsSpecial() );
						pavilionColumnsVo.setParentId( pavilionColumn.getParentId() );

						// 通过栏目id获取资源分类list
						Integer pageNo = reqVo.getPageNumber() == null ? 1 : reqVo.getPageNumber();
						Integer pageSize = reqVo.getPageSize() == null ? 5 : reqVo.getPageSize();
						// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
						PageHelper.startPage( pageNo, pageSize );

						Integer resType = Integer.valueOf( reqVo.getResType() );
						switch (resType) {
						case 1:
							pavilionRelationsPage = BeanUtils.toPagedResult( pavilionsCommonMapper.getFiveRelationsInfoForWebChat( pavilionColumn
									.getMenuId() ) );
							maxCount = pavilionsCommonMapper.getFiveRelationsInfoCountForWebChat( pavilionColumn.getMenuId() );
							pavilionColumnsVo.setMaxCount( maxCount );
							pavilionRelationsList = (List<PavilionRelations>) pavilionRelationsPage.getDataList();
							targetPavilionRelationsList = new ArrayList<PavilionRelations>();
							if (null != pavilionRelationsList && pavilionRelationsList.size() > 0) {
								for (PavilionRelations pavilionRelationsObjVo : pavilionRelationsList) {
									// 五报
									if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianbao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国儿童报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoertongbao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年英语报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianyinyubao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国儿童画报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoertonghuabao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国中学生报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguozhongxueshengbao.jpg" );
									}

									// 十三刊
									else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "幼儿画报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/youerhuabao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "婴儿画报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/yinerhuabao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "嘟嘟熊画报" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/duduxionghuabao.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "我们爱科学" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/womenaikexue.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "儿童文学" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/ertongwenxue.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国卡通" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguokatong.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年儿童" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianertong.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中国少年文摘" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongguoshaonianwenzhai.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "中学生" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhongxuesheng.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "智力课堂" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhiliketang.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "知心姐姐" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/zhixinjiejie.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "辅导员" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/fudaoyuan.jpg" );
									} else if (pavilionRelationsObjVo.getResCategoryName().trim().equals( "少先队小干部" )) {
										pavilionRelationsObjVo.setThumbnail( getStaticPath + "/mobile/shaoxianduixiaoganbu.jpg" );
									} else {
										continue;
									}
									targetPavilionRelationsList.add( pavilionRelationsObjVo );
								}
							}
							pavilionColumnsVo.setPavilionRelationsList( targetPavilionRelationsList );
							pavilionColumnsVoList.add( pavilionColumnsVo );
							break;
						default:
							break;
						}
					}
				}
			}

			menusRelationsInfo.setPavilionColumnsVoList( pavilionColumnsVoList );
		}
		return menusRelationsInfo;
	}

}